package com.epro.dx.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.epro.dx.R;

/**
 * 页面加载动画对话框
 * 
 * @author  hjd008
 * @version  [版本号, 2015-1-6]
 * @see  [相关类/方法]
 * @since  [产品/模块版本]
 */
public class WaitingDialog extends Dialog
{
    
    private String progressText;
    
    private WaitingAreaWidget mWidget;
    
    /**
     * 等待对话框
     * @param context 
     */
    public WaitingDialog(Context context)
    {
        super(context, R.style.loading_dialog);
        setCancelable(true);
        setCanceledOnTouchOutside(false);
    }
    
    /**
     * 等待对话框
     * @param context  
     * @param cancelable  返回键可不可用
     */
    public WaitingDialog(Context context, boolean cancelable)
    {
        super(context, R.style.loading_dialog);
        setCancelable(cancelable);
        setCanceledOnTouchOutside(false);
    }
    
    /**
     * 等待对话框
     * @param context  
     * @param text  
     * @param cancelable 返回键可不可用
     */
    public WaitingDialog(Context context, String text, boolean cancelable)
    {
        super(context, R.style.loading_dialog);
        progressText = text;
        setCancelable(cancelable);
        setCanceledOnTouchOutside(false);
    }
    
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.waiting_dialog_layout);
        View waitingArea = findViewById(R.id.waiting_area);
        mWidget = new WaitingAreaWidget(getContext(), waitingArea);
//        if (!TextUtils.isEmpty(progressText))
//        {
//            mWidget.setText(progressText);
//        }
    }
    
//    public void setProgressText(String text)
//    {
//        this.progressText = text;
//        if (mWidget != null)
//        {
//            mWidget.setText(text);
//        }
//    }
    
    @Override
    protected void onStart()
    {
        super.onStart();
        mWidget.startAnimation();
    }
    
    @Override
    protected void onStop()
    {
        mWidget.stopAnimation();
        super.onStop();
    }
    
    @Override
    public void dismiss()
    {
        super.dismiss();
    }
    
}
